<?php
function __autoload($class_name) {
	$classPath = str_replace('\\', '/', $class_name);
	$filepath = 'alias.php/php/'. $classPath . '.class.php';
//	echo ($filepath."<br/>");
	if (file_exists($filepath)) {
//		echo ("file exists <br/>");
    	require_once $filepath;		
		return true; 
	}
	
	return false;
}

$controller = new ServiceController();

$controller->getParameters();

if ($controller->validateAuthorization())
{
	$s = $controller->getServiceType();
	if ($s ==  $controller::UNKOWN)
		$controller->badRequest();
	
	$controller->execute();
	
	switch ($s) {
		case  $controller::JSON :
			$controller->writeJsonResponse();
			break;
		case  $controller::XML :
			$controller->writeXmlResponse();
			break;
	}
}
else
{
	$controller->unauthorized();
}

$controller->end();
?>

